//
//  MetalViewController.m
//  TouchTest
//
//  Created by fengxijun on 2/17/16.
//  Copyright © 2016 goappbox. All rights reserved.
//

#import "MetalViewController.h"
//#import <Metal/Metal.h>
//#import <MetalKit/MetalKit.h>
//#import <MetalPerformanceShaders/MetalPerformanceShaders.h>
//#import <Metal/MTLCommandQueue.h>
//#import "UIImage+Extesion.h"
//#import <Metal/MTLTexture.h>

@interface MetalViewController ()
//<
//    MTKViewDelegate
//>
//{
//    MTKView *metalView;
//    id<MTLCommandQueue> commandQueue;
//    id<MTLTexture> sourceTexture;
//}
@property (nonatomic,strong) UISlider *blurRadius;
@end

@implementation MetalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor whiteColor];
//    _blurRadius = [[UISlider alloc] initWithFrame:CGRectMake(30.f, 30.f, self.view.frame.size.width - 60.f, 44.f)];
//    [_blurRadius setMaximumValue:100.f];
//    [_blurRadius setMinimumValue:0.f];
//    [_blurRadius addTarget:self action:@selector(blurRadiusDidChanged:) forControlEvents:UIControlEventValueChanged];
//    [self.view addSubview:_blurRadius];
    
//    [self setUpMetalView];
//    [self loadAssets];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//- (void) drawInMTKView:(MTKView *)view
//{
//    id<MTLCommandBuffer> commandBuffer = [commandQueue commandBuffer];
//    MPSImageGaussianBlur *gaussianblur = [[MPSImageGaussianBlur alloc] initWithDevice:metalView.device sigma:self.blurRadius.value];
//    [gaussianblur encodeToCommandBuffer:commandBuffer sourceTexture:sourceTexture destinationTexture:[[view currentDrawable] texture]];
//    [commandBuffer presentDrawable:view.currentDrawable];
//    [commandBuffer commit];
//}
//
//- (void) blurRadiusDidChanged:(UISlider *)slider {
//    [metalView setNeedsDisplay];
//}
//
//- (void) mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size
//{
//}
//
//- (void) setUpMetalView
//{
//    metalView = [[MTKView alloc] initWithFrame:CGRectMake(0.f, 0.f, 300.f, 300.f)];
//    metalView.center = self.view.center;
//    metalView.layer.borderColor = [UIColor whiteColor].CGColor;
//    metalView.layer.borderWidth = 5.f;
//    metalView.layer.cornerRadius = 20.f;
//    metalView.clipsToBounds = true;
//    [self.view addSubview:metalView];
//    
//    metalView.device = MTLCreateSystemDefaultDevice();
//    if (!MPSSupportsMTLDevice(metalView.device)) {
//        NSLog(@"MPSSupportsMTLDevice(metalView.device)");
//        return;
//    }
//    
//    metalView.delegate = self;
//    metalView.depthStencilPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
//    
//    metalView.colorPixelFormat = MTLPixelFormatBGRA8Unorm;
//    metalView.framebufferOnly = false;
//    
//}
//
//- (void) loadAssets {
//    commandQueue = [metalView.device newCommandQueue];
//    MTKTextureLoader *textureLoader = [[MTKTextureLoader alloc] initWithDevice:metalView.device];
//    UIImage *image = [UIImage imageNamed:@"touxiang1"];
//    UIImage *mirrorImage = [UIImage imageWithCGImage:image.CGImage scale:1.f orientation:UIImageOrientationDownMirrored];
//    UIImage *scaledImage = [UIImage scaleToSize:mirrorImage size:CGSizeMake(600.f, 600.f)];
//    
//    @try {
//        sourceTexture = [textureLoader newTextureWithCGImage:scaledImage.CGImage options:nil error:nil];
//    }
//    @catch (NSException *exception) {
//        NSLog(@"%@",exception);
//    }
//    
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
